package site.yunnong.atvris.admin.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.UserDetailsService;
import site.yunnong.atvris.dao.admin.service.SysAdminManageService;
import site.yunnong.atvris.dao.security.config.SecurityConfig;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-06日
 */
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class YunnongSecurityConfig extends SecurityConfig {

    @Autowired
    private SysAdminManageService sysAdminManageService;

    // 有了这一条，spring security就不会在console中debug 密码
    @Bean
    public UserDetailsService adminDetailsService() {
        //获取登录用户信息
        return username -> sysAdminManageService.loadAdminByUsername(username);
    }
}
